<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>6-去除空格</title>
</head>
<body>
<script>
	var str = ' 中国 西安  ';
	str = str.trim();
	//alert("中国西安".length);4
	alert(str);
	alert(str.length);//5
	str=str.replace(/\s+/g,"");
	alert(str.length);
</script>
</body>
</html>